[#include "/WEB-INF/pages/common/taglibs.ftl"]
[@c.url	var="deleteItemUrl" value='/manage/Config_deleteItem.action' scope="page"]
	[@c.param name="backUrl" value="${currentUrl}"/]
[/@c.url];
[#macro _script]
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.alerts.js'/]"></script>
	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
				// 创建
				$('#createConfigItem').unbind('click').click(function() {
					[@c.url	var="createUrl" value='/manage/Config_create.action' scope="page"]
						[@c.param name="backurl" value="${currentUrl}"/]
					[/@c.url]
					var	url	= "${createUrl}";
					$.get(url, {'ajax':'true'}, function(data) {
						$('.config_edit').html(data);
						base.init();
					})
					
				})
			};
			
			function _jqxComponentRender() {
				// 增加子项事件绑定
				$('button', '#addConfigItem').unbind('click').click(function() {
					var size = $('.config_item').length;
					$('#addConfigItem').before("<span class='field config_item'>"
					+"标题：<input style='width:80px;' name='config.configItemList[" + size + "].name' value='' />"
					+"&nbsp;键名：<input style='width:80px;' name='config.configItemList[" + size + "].key' value='' />"
					+"&nbsp;键值：<input style='width:80px;' name='config.configItemList[" + size + "].value' value='' />"
					+" <a href='javascript:;' style='width:50px;' class='stdbtn radius2 item-delete'>删除</a></span>");
					_itemDeleteEventListener()
					return false;
				})
			}
			
			// item-delete
			function _itemDeleteEventListener() {
				// 删除按钮
				$('.item-delete').unbind().click(function() {
					var _$item = $(this);
					var id = _$item.attr('delId');
					var flag = false;
					if (id != null) {
						flag = true;
					/*
						var content = "配置项删除后将无法恢复,是否仍要删除?";
						var title = "删除配置项";
						jConfirm(content, title, function(r) {
							if (r) {
								flag = true;
							}
						});
						return flag;
					*/
					} 
					_$item.parents('.config_item').fadeOut("slow", function(){
						$(this).remove();
					})
					return flag;
				})
			}
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                    _addEventListeners();
                    _jqxComponentRender();
                    _itemDeleteEventListener();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/Config_site.action?currentPage=${currentPage}' /]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]
[#if piece==true]
	[@_script /]
	<!--设置提交行为-->
	[#assign act="update" /]
	[#include "/WEB-INF/pages/manage/Config/_config.ftl"]
[#else]
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Insert title here</title>
	<meta name="menu" content="CategoryMenu"/> 
	<meta name="heading" content="heading"/>
	
	[@_script /]
</head>
<body id="body">
	<div class="contenttitle">
    	<h2 id="vertical" class="form"><span>配置编辑</span></h2>
    </div><!--contenttitle-->
    <br>
	<!--设置提交行为-->
	[#assign act="update" /]
	[#include "/WEB-INF/pages/manage/Config/_config.ftl"]
</body>
</html>
[/#if]